<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>如输入的值大于100显示一个信息</title>
</head>

<body>
    <p>输入数字并点击验证按钮:</p>
    <input id="id1" type="number" max="100">
    <button onclick="myFunction()">验证</button>
    <p>如果输入的数字大于 100 ( input 的 max 属性), 会显示错误信息。</p>
    <p id="demo"></p>
    <script>
        function myFunction() {
            var txt = "";
            if (document.getElementById("id1").validity.rangeOverflow) {
                txt = "输入的值太大了";
            } else {
                txt = "输入正确";
            }
            document.getElementById("demo").innerHTML = txt;
        }
    </script>
</body>

</html>